package com.cy.pj.ajax.controller;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
public class AjaxLibController {
    @RequestMapping("doPostJSON")
    public String doPostJSON(@RequestBody Map<String,Object> map){
        System.out.println("map="+map);
        return "post ok";
    }

    @RequestMapping("doPost")
    //使用map作为参数接受请求参数时用@RequestParam修饰
    public String doPost(@RequestParam Map<String,Object> map){
        System.out.println("map"+map);
        return "post ok";
    }

    @RequestMapping("doGet")
    public Map<String,Object> doGet(){
        Map<String,Object> map =new HashMap<>();
        map.put("code", 1);
        map.put("message", "success");
        return map;
    }

    @RequestMapping("doAjax")
    public String doAjax(String msg){
        System.out.println("msg"+msg);
        return msg+"toUppercase()"+msg.toUpperCase();
    }
}
